package cn.sccl.test.lazy_fetch;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.Test;

import cn.sccl.domain.Customer;
import cn.sccl.domain.LinkMan;
import cn.sccl.utils.HibernateUtils;

/**
 * @author raoshuang
 * @date 2019年8月28日下午3:01:01
 * @version 1.0.0
 * 关联级别 延迟加载 & 抓取策略
 */
public class LazyFetchDemo2 {
	@Test
	//fetch:select	单表查询
	//lazy:proxy  
		//customer-true 懒加载
	public void fun1(){
		Session session = HibernateUtils.openSession();
		Transaction tx = session.beginTransaction();
		
		LinkMan lm = session.get(LinkMan.class, 3l);
		Customer customer = lm.getCustomer();
		System.out.println(customer);
		
		tx.commit();
		session.close();
	}
	@Test
	//fetch:join	多表
	//lazy: 失效  
	public void fun3(){
		Session session = HibernateUtils.openSession();
		Transaction tx = session.beginTransaction();
		
		LinkMan lm = session.get(LinkMan.class, 3l);
		Customer customer = lm.getCustomer();
		System.out.println(customer);
		
		tx.commit();
		session.close();
	}
	@Test
	//fetch:select	单表查询
	//lazy:proxy  
		//customer-false 立即加载
	public void fun2(){
		Session session = HibernateUtils.openSession();
		Transaction tx = session.beginTransaction();
		
		LinkMan lm = session.get(LinkMan.class, 3l);
		Customer customer = lm.getCustomer();
		
		System.out.println(customer);
		tx.commit();
		session.close();
	}
}
